--[[
    player class class
]]--

Optimizer.Class = {};
Optimizer.Class_mt = { __index = Optimizer.Class };

Optimizer.Class.spellLib = {};

function Optimizer.Class:new()
    local new_inst = {
    };   -- the new instance
    setmetatable( new_inst, Optimizer.Class_mt ); -- all instances share the same metatable
    return new_inst;  
end


function Optimizer.Class:AddSpell(spell)
    if spell.name == nil then
        DEFAULT_CHAT_FRAME:AddMessage("Optimizer.Class: AddSpell requires a name");
    else
        self.spellLib[spell.name] = spell;
    end    
end

function Optimizer.Class:registerSpells()
    if self.spellLib ~= nil then
        for spellName,spell in pairs(self.spellLib) do
            if spell:exists() then
                spell:init();
                for event,func in pairs(spell.Events) do
                    Optimizer.regSpell(event,spellName,func);
                end
            end
        end
    end
end

function Optimizer.Class:onCombat(time)
    for i,v in pairs(self.spellLib) do
        v:onCombat(time);
    end
    table.sort(Optimizer._UpdateShedule,Optimizer.CompShedule);
end

function Optimizer.Class:GetPower()
    return UnitPower("player");
end

